package com.aaa.controller;

import com.aaa.aspect.InsertAnn;
import com.aaa.aspect.UpdateAnn;
import com.aaa.entity.MyReturn;
import com.aaa.entity.TblTestPlanSas;
import com.aaa.entity.TestPlanFpa;
import com.aaa.service.TblTestPlanSasService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;

/**
 * 测试计划fpa(TblTestPlanSas)表控制层
 *
 * @author makejava
 * @since 2022-07-15 17:36:55
 */
@RestController
@RequestMapping("tblTestPlanSas")
public class TblTestPlanSasController extends BaseController{
    /**
     * 服务对象
     */
    @Resource
    private TblTestPlanSasService tblTestPlanSasService;
    MyReturn myReturn=new MyReturn();

    @RequestMapping("toShowTestPlanSas.do")
    public ModelAndView toShowTestPlanSas(ModelAndView modelAndView){
        modelAndView.setViewName("showTestPlanSas");
        return modelAndView;
    }
    /**
     * 分页查询
     *
     * @param tblTestPlanSas 筛选条件
     * @param tblTestPlanSas    分页对象
     * @return 查询结果
     */
    @RequestMapping("queryByPage.do")
    public ResponseEntity<Page<TblTestPlanSas>> queryByPage(TblTestPlanSas tblTestPlanSas,Integer page ,Integer limit) {
        PageRequest pageRequest=  PageRequest.of(page-1,limit);
        return ResponseEntity.ok(this.tblTestPlanSasService.queryByPage(tblTestPlanSas, pageRequest));
    }


    /**
     * 新增数据
     *
     * @param tblTestPlanSas 实体
     * @return 新增结果
     */
    @PostMapping("insertPlan.do")
    @InsertAnn
    public MyReturn add(TblTestPlanSas tblTestPlanSas) {
        boolean insert = this.tblTestPlanSasService.insert(tblTestPlanSas);
        if (insert) {
            return getSuccessResult(myReturn);
        }
        return getFailResult(myReturn);
    }

    /**
     * 编辑数据
     *
     * @param tblTestPlanSas 实体
     * @return 编辑结果
     */
    @RequestMapping("updatePlanSas.do")
    @UpdateAnn
    public MyReturn edit(TblTestPlanSas tblTestPlanSas) {
        boolean update = this.tblTestPlanSasService.update(tblTestPlanSas);
        if (update) {
            return getSuccessResult(myReturn);
        }
        return getFailResult(myReturn);    }

    /**
     * 删除数据
     *
     * @param idList 主键
     * @return 删除是否成功
     */
    @RequestMapping("deletePlanSas.do")
    public MyReturn deleteById(String idList) {
        boolean b = this.tblTestPlanSasService.deleteById(idList);
        if (b){
            return getSuccessResult(myReturn);
        }
        return getFailResult(myReturn);
    }

    /**
     * @create by: feng (zhaixing@163.com)
     * @description: 题目唯一性校验
     * @create time: 2022/7/15 15:05
     * @param tblTestPlanSas
     * @return MyReturn
     */
    @RequestMapping("repetitionName.do")
    public MyReturn repetitionName(TblTestPlanSas tblTestPlanSas){
        boolean b = this.tblTestPlanSasService.repetitionName(tblTestPlanSas);
        if (b) {
            return getSuccessResult(myReturn);
        }
        return getFailResult(myReturn);
    }

}

